package com.songlanyun.modules.aboutus.service.impl;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.Query;

import com.songlanyun.modules.aboutus.dao.AboutUsDao;
import com.songlanyun.modules.aboutus.entity.AboutUsEntity;
import com.songlanyun.modules.aboutus.service.AboutUsService;


@Service("aboutUsService")
public class AboutUsServiceImpl extends ServiceImpl<AboutUsDao, AboutUsEntity> implements AboutUsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<AboutUsEntity> page = this.page(
                new Query<AboutUsEntity>().getPage(params),
                new LambdaQueryWrapper<AboutUsEntity>()
                        .orderByAsc(AboutUsEntity::getSequence)
                        .orderByDesc(AboutUsEntity::getCreateTime)
        );

        return new PageUtils(page);
    }


    @Override
    public List<AboutUsEntity> appList(Map<String, Object> params) {
        Integer limit = MapUtil.getInt(params, "limit");

        return this.baseMapper.selectList(
                new LambdaQueryWrapper<AboutUsEntity>()
                        .last(ObjectUtil.isNotNull(limit), "limit " + limit)
                        .orderByAsc(AboutUsEntity::getSequence)
                        .orderByDesc(AboutUsEntity::getCreateTime)
        );
    }

}
